#include <stdio.h>
#include <unistd.h> 

void writeTo(int val, int index);
void readFrom(int* res, int* index);


void writeTo(int val, int index) {
	FILE *fp;
	fp = fopen("file.txt","w"); 
		
    fprintf(fp,"%d %d",val, index); 
    fclose(fp); 
	
}

void readFrom(int* res, int* index) {
	FILE *fp;
	fp = fopen("file.txt", "r");
	fscanf(fp, "%d %d", res, index);
	fclose(fp); 
	
	
	//return result;
}

int main() {
	
	writeTo(33,0);
	
	int res;
	int index;
	readFrom(&res, &index);
	printf("wartosc to: %d\n", res);
	
	int tab[6];
	tab[0] = 11;
	tab[1] = 45;
	tab[2] = 110;
	tab[3] = 5;
	tab[4] = 99;
	tab[5] = 1100;
	
	
	
	pid_t process;
	while(index<5) {
		
		process = fork();
		readFrom(&res, &index);
		writeTo(res + tab[index], index+1);
	}
	

	
	getchar(); 
	
	return 0;
}